package com.dyava.commons.lang;

import com.eaio.util.lang.Hex;
import com.eaio.uuid.UUID;

public class UUIDUtils {
	private UUIDUtils(){}

	public static String getUUID() {
		UUID uuid = new UUID();
		StringBuilder out = new StringBuilder(36);
		Hex.append(out, (int) (uuid.getTime() >> 32)) ;
		Hex.append(out, (short) (uuid.getTime() >> 16)) ;
		Hex.append(out, (short) uuid.getTime()) ;
		Hex.append(out, (short) (uuid.getClockSeqAndNode() >> 48)) ;
		Hex.append(out, uuid.getClockSeqAndNode(), 12);
		return out.toString();
	}
	/**
	 * 有序的uuid
	 * @return
	 * @author Administrator
	 * @create 2017-7-19 上午10:11:26
	 */
	public static String getOrderlyUUID(){
		UUID uuid = new UUID();
		StringBuilder out = new StringBuilder(36);
		Hex.append(out, (short) uuid.getTime()); //时间高位
		Hex.append(out, (short) (uuid.getTime() >> 16)); //时间中位
    	Hex.append(out, (int) (uuid.getTime() >> 32));   //时间低位
		Hex.append(out, uuid.getClockSeqAndNode(), 12);  //节点
		Hex.append(out, (short) (uuid.getClockSeqAndNode() >> 48)); //进程？
		return out.toString();
	}
}
